home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_024 / conquest / conqve.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  17KB  |  368 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "structs.h"
  4. #include "vars.h"
  5.  
  6. inv_enemy(x,y, planet)
  7. struct stplanet *planet;
  8. {
  9.         int num,inv_amount,balance,min_mb,transports,new_tf;
  10.         int trash1, trash2;
  11.  
  12.         balance = planet->iu;
  13.         if ( tf_stars[planet->pstar][ENEMY]==0 ) {
  14.                 get_tf(ENEMY,&new_tf,planet->pstar);
  15.                 tf_stars[planet->pstar][ENEMY]=1;
  16.         } 
  17.         else { /*use present tf*/
  18.                 new_tf = 1;
  19.                 while ( (tf[ENEMY][new_tf].dest != planet->pstar) || (tf[
  20.                     ENEMY][new_tf].eta != 0) ) new_tf = new_tf + 1;
  21.         };
  22.         min_mb = planet->capacity / 20;
  23.         while ( ((planet->amb==0) && (! planet->conquered) &&
  24.             (planet->mb < min_mb) && (balance >= mb_cost))) {
  25.                 balance = balance - mb_cost;
  26.                 planet->mb = planet->mb+1;
  27.         };
  28.         if ( ( balance >= b_cost) && (rnd(5) != 1) && (rnd(07) <= planet->amb+3)
  29.             &&
  30.             (planet->amb > 1) ) {
  31.                 balance = balance - b_cost;
  32.                 tf[ENEMY][new_tf].b ++;
  33.         };
  34.         if ( (balance >= amb_cost) && ((planet->amb< 4) || (rnd(2)==2))
  35.             && (! planet->conquered) ) {
  36.                 balance = balance - amb_cost;
  37.                 planet->amb++;
  38.         };
  39.         while ( balance >= 9 ) {
  40.                 switch ( rnd(12) ){
  41.                 case 1: 
  42.                 case 2: 
  43.                         research(ENEMY,en_research,8);
  44.                         balance = balance-8;
  45.                         break;
  46.  
  47.                 default:
  48.                         inv_amount = min(3,planet->inhabitants*iu_ratio - planet->iu);
  49.                         balance = balance - i_cost * inv_amount;
  50.                         planet->iu = planet->iu + inv_amount;
  51.                         break;
  52.  
  53.                 case 3: 
  54.                 case 4:
  55.                 case 10:
  56.                         if ( balance >= c_cost ) {
  57.                                 balance = balance - c_cost;
  58.                                 tf[ENEMY][new_tf].c++;
  59.                         } 
  60.                         else if ( (! planet->conquered) && (balance >= mb_cost)
  61.                             ) {
  62.                                 balance = balance - mb_cost;
  63.                                 planet->mb = planet->mb + 1;
  64.                         } 
  65.                         else {
  66.                                 balance = balance - 9;
  67.                                 research(ENEMY,en_research,9);
  68.                         };
  69.                         break;
  70.  
  71.                 case 11: 
  72.                 case 12:
  73.                         if ( ((float)planet->inhabitants/planet->capacity < 0.6) ||
  74.                             ((planet->capacity >= b_cost / iu_ratio) && (planet->iu <
  75.                             b_cost+10)) ) { /*no t"s*/
  76.                                 inv_amount = min(3,planet->inhabitants * iu_ratio - planet->iu);
  77.                                 balance = balance - inv_amount * i_cost;
  78.                                 planet->iu = planet->iu + inv_amount;
  79.                         } 
  80.                         else /*build transports*/
  81.                                 if(!(planet->conquered)) {
  82.                                         transports = min(rnd(2)+6,planet->inhabitants-1);
  83.                                         if ( planet->iu > b_cost )
  84.                                                 transports = min(transports,planet->iu - b_cost);
  85.                                         balance = balance - transports;
  86.                                         planet->inhabitants = planet->inhabitants - transports;
  87.                                         trash1 = planet->iu - transports;
  88.                                         trash2 = planet->inhabitants * iu_ratio;
  89.                                         planet->iu = min(trash1, trash2);
  90.                                         tf[ENEMY][new_tf].t = tf[ENEMY][new_tf].t + transports;
  91.                                 };
  92.                         break;
  93.                         /*
  94.                              balance = balance - s_cost;
  95.                              tf[ENEMY][new_tf].s = tf[ENEMY][new_tf].s + 1;
  96.                              if ( debug ) write(tty, "s ");
  97.                          */
  98.                 }; /*switch (*/
  99.         }; /*while (*/
  100.         zero_tf(ENEMY,new_tf);
  101.         research(ENEMY,en_research,balance);
  102. }
  103.  
  104. inv_player(x,y,planet)
  105. struct stplanet *planet;
  106. {
  107.         boolean printtf; 
  108.         char iline[81]; 
  109.         char key;
  110.         int cost,amount,ind,new_tf,balance;
  111.         int trash1, trash2;
  112.  
  113.         get_tf(player,&new_tf,planet->pstar);
  114.         tf_stars[planet->pstar][player]++;
  115.         printtf = false;
  116.         balance=planet->iu;
  117.         cle3r_left();
  118.         point(1,19);
  119.         putchar(planet->pstar+'A'-1);
  120.  
  121.         printf("%d:%2d                         ", planet->number, planet->psee_capacity);
  122.         point(x_cursor + 5, y_cursor);
  123.         x_cursor = x_cursor - 5;
  124.         printf("(%2d,/%3d)", planet->inhabitants, planet->iu);
  125.         if ( planet->conquered )
  126.                 printf("Con");
  127.         else
  128.                 printf("   ");
  129.         if ( planet->mb!=0 )
  130.                 printf("%2dmb", planet->mb);
  131.         else
  132.                 printf("    ");
  133.         if ( planet->amb!=0 )
  134.                 printf("%2damb", planet->amb);
  135.         point(x_cursor,y_cursor + 1);
  136.  
  137.         do {
  138.                 point(1,18);
  139.                 printf("%3d?                          ", balance);
  140.                 point(5,18);
  141.                 get_line(iline,&ind,false);
  142.                 do {
  143.                         get_token(iline,&ind,&amount,&key);
  144.                         switch ( key ){
  145.                         case 'A': 
  146.                                 cost=amount*amb_cost;
  147.                                 if ( planet->inhabitants ==0 ) {
  148.                                         cost = 0;
  149.                                         error_message();
  150.                                         printf("  !abandoned planet");
  151.                                 } 
  152.                                 else if (planet->conquered) {
  153.                                         cost =0;
  154.                                         error_message();
  155.                                         printf(" !No amb  on conquered colony ");
  156.                                 } 
  157.                                 else
  158.                                         if ( cost<=balance ) {
  159.                                                 planet->amb=planet->amb+amount;
  160.                                         };
  161.                                 break;
  162.                         case 'B': 
  163.                                 cost=amount * b_cost;
  164.                                 if ( cost<=balance ) {
  165.                                       tf[player][new_tf].b=tf[player][new_tf].b
  166.                                                                 + amount;
  167.                                         printtf = true;
  168.                                 };
  169.                                 break;
  170.                         case 'C': 
  171.                                 cost=amount * c_cost;
  172.                                 if ( cost <= balance ) {
  173.                                      tf[player][new_tf].c=tf[player][new_tf].c
  174.                                                                 + amount;
  175.                                         printtf = true;
  176.                                 };
  177.                                 break;
  178.                         case 'H': 
  179.                                 help(4);
  180.                                 cost = 0;
  181.                                 break;
  182.                         case 'M': 
  183.                                 cost=amount * mb_cost;
  184.                                 if ( planet->inhabitants ==0 ) {
  185.                                         cost =0;
  186.                                         error_message();
  187.                                         printf("  !abandoned planet");
  188.                                 } 
  189.                                 else if (planet->conquered) {
  190.                                         cost =0;
  191.                                         error_message();
  192.                                         printf(" !No Mb  on conquered colony  ");
  193.                                 } 
  194.                                 else
  195.                                         if ( cost <= balance ) {
  196.                                                 planet->mb=planet->mb+amount;
  197.                                         };
  198.                                 break;
  199.                         case 'S': 
  200.                                 cost= amount * s_cost;
  201.                                 if ( cost <= balance ) {
  202.                                      tf[player][new_tf].s=tf[player][new_tf].s
  203.                                                                 + amount;
  204.                                         printtf = true;
  205.                                 };
  206.                                 break;
  207.                         case 'T': 
  208.                                 cost= amount;
  209.                                 if ( cost <= balance ) {
  210.                                         if ( cost > planet->inhabitants ) {
  211.                                                 error_message();
  212.                                                 printf(" ! Not enough people for ( trans");
  213.                                                 cost=0;
  214.                                         } 
  215.                                         else if ( planet->conquered ) {
  216.                                                 cost = 0;
  217.                                                 error_message();
  218.                                                 printf( "!No transports on conqered col");
  219.                                         } 
  220.                                         else {
  221.                                                 tf[player][new_tf].t=tf[player][new_tf].t+amount;
  222.                                                 planet->inhabitants=planet->inhabitants-amount;
  223.                                                 trash1 = planet->iu - amount;
  224.                                                 trash2 = planet->inhabitants * iu_ratio;
  225.                                                 planet->iu = min(trash1, trash2);
  226.                                                 printtf = true;
  227.                                                 if ( planet->inhabitants==0 ) {
  228.                                                         col_stars[planet->pstar][player]--;
  229.                                                         if ( col_stars[planet->pstar][player]==0 ) {
  230.                                                                 board[x][y].enemy = ' ';
  231.                                                                 update_board(x,y,left);
  232.                                                         };
  233.                                                         planet->team=none;
  234.                                                         planet->amb=0; 
  235.                                                         planet->mb=0; 
  236.                                                         planet->iu=0;
  237.                                                 };
  238.                                         };
  239.                                 };
  240.                                 break;
  241.                         case 'I': 
  242.                                 cost= i_cost * amount;
  243.                                 if ( (amount + planet->iu) > (planet->inhabitants*iu_ratio)
  244.                                     ) {
  245.                                         cost = 0;
  246.                                         error_message();
  247.                                         printf(" !Can't support that many iu's");
  248.                                 } 
  249.                                 else if ( cost <= balance ) {
  250.                                         planet->iu=planet->iu+amount;
  251.                                 };
  252.                                 break;
  253.                         case 'R': 
  254.                         case 'V': 
  255.                         case 'W':
  256.                                 cost=amount;
  257.                                 if ( cost <= balance ) {
  258.                                         point(1,21);
  259.                                         research(player,key,amount);
  260.                                 };
  261.                                 pr2nt_res(key);
  262.                                 break;
  263.                         case ' ': 
  264.                                 cost=0; 
  265.                                 break;
  266.                         case '>': 
  267.                                 cost=0;
  268.                                 point(1,18);
  269.                                 printf(">?     ");
  270.                                 point(3,18);
  271.                                 get_char(&key);
  272.                                 switch ( key ){
  273.                                 case 'M':
  274.                                         printmap(); 
  275.                                         break;
  276.                                 case 'S':
  277.                                         starsum(); 
  278.                                         break;
  279.                                 case 'C':
  280.                                         print_col(); 
  281.                                         break;
  282.                                 case 'R': 
  283.                                         ressum(); 
  284.                                         break;
  285.                                 default:
  286.                                         error_message();
  287.                                         printf(" !Only M,S,C,R allowed      ");
  288.                                 }; /*switch ( > */
  289.                                 break;
  290.                         default:
  291.                                 error_message();
  292.                                 printf(" !Illegal field %c",key);
  293.                         }; /*switch (*/
  294.                         if ( cost > balance ) {
  295.                                 error_message();
  296.                                 printf(" !can't affort %3d%c", amount, key);
  297.                         }
  298.                         else
  299.                                 balance = balance - cost;
  300.                 } 
  301.                 while (key != ' ');
  302.                 cle3r_left();
  303.                 point(1,19);
  304.                 putchar(planet->pstar+'A'-1);
  305.  
  306.         printf("%d:%2d                         ", planet->number, planet->psee_capacity);
  307.         point(x_cursor + 5, y_cursor);
  308.         x_cursor = x_cursor - 5;
  309.         printf("(%2d,/%3d)", planet->inhabitants, planet->iu);
  310.         if ( planet->conquered )
  311.                 printf("Con");
  312.         else
  313.                 printf("   ");
  314.         if ( planet->mb!=0 )
  315.                 printf("%2dmb", planet->mb);
  316.         else
  317.                 printf("    ");
  318.         if ( planet->amb!=0 )
  319.                 printf("%2damb", planet->amb);
  320.         point(x_cursor,y_cursor + 1);
  321.  
  322.                 if ( printtf ) {
  323.                         point(1,20);
  324.                         pr3nt_tf(new_tf);
  325.                 };
  326.         } 
  327.         while (balance > 0);
  328.         zero_tf(player,new_tf);
  329.         on_board(x,y);
  330. }
  331.  
  332. invest()
  333. {
  334.         int newborn,starnum; 
  335.         struct stplanet  *pplan;
  336.         production_year = 0;
  337.         point(33,20);
  338.         printf("* investment *  ");
  339.         for ( starnum= 1 ; starnum<=nstars; starnum++ ) {
  340.                 pplan= stars[starnum].first_planet;
  341.                 while ( pplan!=nil ) {
  342.                         if ( ((pplan->esee_team) == player) 
  343.                             && ((pplan->capacity) > 10)
  344.                             && ((pplan->esee_def) < 12) )
  345.                                 pplan->esee_def = (pplan->esee_def) + 1;
  346.                         if ( (pplan->team) != none ) {
  347.                                 newborn= round((pplan->inhabitants)
  348.                                     * growth_rate[pplan->team] *
  349.                                     (1-((pplan->inhabitants)/(pplan->capacity))));
  350.                                 if ( pplan->conquered )
  351.                                         newborn = newborn / 2;
  352.                                 pplan->inhabitants= (pplan->inhabitants) 
  353.                                                                 + newborn;
  354.                                 pplan->iu = (  pplan->iu) + newborn;
  355.                                 if ( pplan->team==ENEMY )
  356.                                         inv_enemy(stars[starnum].x,
  357.                                                 stars[starnum].y,pplan);
  358.                                 else
  359.                                         inv_player(stars[starnum].x,
  360.                                                 stars[starnum].y,pplan);
  361.                         };
  362.                         pplan=pplan->next;
  363.                 };
  364.         };
  365.         battle();
  366. }
  367.  
  368.